package com.jinlia.show.modules.base.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinlia.show.modules.base.model.po.SysUserPO;
import com.jinlia.show.modules.base.system.entity.SysUserRole;
import com.jinlia.show.modules.base.system.mapper.SysUserRoleMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SysUserRoleMapperService extends ServiceImpl<SysUserRoleMapper, SysUserRole> {
    public void updateUserRoleByUserId(SysUserPO sysUserVO) {
        this.lambdaUpdate()
                .eq(SysUserRole::getUserId, sysUserVO.getId())
                .remove();
        sysUserVO.getRoles().forEach(role -> {
            SysUserRole sysUserRole = new SysUserRole(sysUserVO.getId(), role.getId());
            this.save(sysUserRole);
        });
    }
}
